package com.llkj.qingnianguoxue.home;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;

import com.llkj.qingnianguoxue.R;
import com.llkj.qingnianguoxue.base.BaseFragment;
import com.llkj.qingnianguoxue.http.HttpMethod;

/**
 * 大师详情——简介
 */
public class MasterDescriptionFragment extends BaseFragment {
    private WebView webView;
    private String mMasterId;//大师id

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_master_description, container, false);
        Bundle bundle = getArguments();
        mMasterId = bundle.getString("master_id");

        initView();
        initListener();
        return rootView;
    }
    private void initView(){
        webView = (WebView) rootView.findViewById(R.id.webView);
        WebSettings settings = webView.getSettings();
        //支持javascript
        settings.setJavaScriptEnabled(true);
        //自适应屏幕
        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        settings.setLoadWithOverviewMode(true);

        String webUrl = String.format(HttpMethod.ARTIST_DETAILS_ABSTRACT,mMasterId,"1");
        webView.loadUrl(webUrl);
    }

    private void initListener(){
        webView.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                if (newProgress == 100) {
                    // 网页加载完成
                    dismissWaitDialog();
                } else {
                    // 加载中
                }
            }
        });
    }
}
